package com.lexicalAnalyzer;


import java.util.ArrayList;
import java.util.HashMap;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: Lenovo
 * Date: 11.11.2012
 * Time: 23:31
 * To change this template use File | Settings | File Templates.
 */

public abstract class ScannerBase
{
    protected FlexLexer lexer;
    ArrayList<String> keyWords;
    private HashMap<String, TokenCode> keywordMap = null;
     Token m_currentToken;



    public abstract Token nextToken() throws IOException;

    /**
     * Sets the current token
     * @param token The Token object for the last token read.
     */
    protected abstract void setCurrentToken(Token token);

    /**
     * Inspects a lexeme to check whether it's a keyword.
     * @param lexeme The lexeme to check
     * @return If the lexeme is a keyword then the appropriate {@link TokenCode} is returned; otherwise {@link TokenCode}.ID.
     */
    protected abstract TokenCode getKeywordCode(String lexeme);
    /**
     * Gets a hash map that maps keyword lexemes to token codes.
     * @return A generic hash map.
     */



    protected HashMap<String, TokenCode> getKeywordMap() {
        if (keywordMap == null)
        {
            // MA BREYTA RÖÐUNINIA EITTHVAÐ KANNSKI

            keywordMap = new HashMap<String, TokenCode>();
            keywordMap.put("program", TokenCode.PROGRAM);
            keywordMap.put("begin", TokenCode.BEGIN);
            keywordMap.put("end", TokenCode.END);
            keywordMap.put("array", TokenCode.ARRAY);
            keywordMap.put("of", TokenCode.OF);
            keywordMap.put("integer", TokenCode.INTEGER);
            keywordMap.put("real", TokenCode.REAL);
            keywordMap.put("function", TokenCode.FUNCTION);
            keywordMap.put("procedure", TokenCode.PROCEDURE);
            keywordMap.put("end", TokenCode.END);
            keywordMap.put("if", TokenCode.IF);
            keywordMap.put("then", TokenCode.THEN);
            keywordMap.put("else", TokenCode.ELSE);
            keywordMap.put("while", TokenCode.WHILE);
            keywordMap.put("do", TokenCode.DO);
            keywordMap.put("not", TokenCode.NOT);
            keywordMap.put("var", TokenCode.VAR);
        }

        return keywordMap;
    }


}
